function [t, e] = simulate(program, architecture, postscript, trace)
% [t, e] = simulate(program, architecture, postscript)

arglist = [program ' ' architecture];

if nargin > 2
  arglist = [arglist ' ' postscript];
end

if nargin > 3
  arglist = [arglist ' ' trace];
end

[o, f] = gcbo;

pointer = get(f, 'Pointer');
set(f, 'Pointer', 'watch');

drawnow;

[status, result] = system(['/home/wcaarls/src/sc/dse/simulate.py ' ...
		    arglist]);

set(f, 'Pointer', pointer);

if status ~= 0
  disp('Simulation failed');
  disp(result);
  t = 0;
  e = 0;
  return
end

start = strfind(result, '% *** CUT HERE ***');
eval(result(start:end));

